package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author 老杨
 * @version 1.0
 * 分类 接口
 */
@Api(tags = "分类管理接口")
@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
  CategoryService categoryService;

    @ApiOperation(value = "分页查询和条件查询")
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult page = categoryService.page(categoryPageQueryDTO);
        return Result.success(page);
    }


    @ApiOperation(value = "新增分类")
    @PostMapping
    public Result add(@RequestBody CategoryDTO categoryDTO){
        categoryService.add(categoryDTO);
        return Result.success();
    }

    @ApiOperation(value = "删除分类")
    @DeleteMapping
    public Result delete(Integer id){
        categoryService.delete(id);
        return Result.success();
    }

    @ApiOperation(value = "修改分类")
    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }

    @ApiOperation(value = "禁用启用 分类")
    @PostMapping("/status/{status}")
    public Result openordiable(@PathVariable Integer status,Long id){
        categoryService.openordisable(status,id);
        return Result.success();
    }

@ApiOperation(value = "返回类别接口")
    @GetMapping("/list")
    public Result<List<Category>> list(Integer type){
    List<Category> list = categoryService.list(type);
    return Result.success(list);
}

}
